<?php
/**
 * WithdrawController.class.php
 * 提现管理控制器
 *
 * @author  朱伟东
 *
 *
 */
namespace Admin\Controller;
/**
 * 提现管理控制器
 *
 * @package Admin\Controller
 */
class WithdrawController extends BaseController {
    private $status_titles = array('未通过','已通过','待审核');
    /**
     * 提现管理首页
     */
    public function index(){
        $status = I('get.status');
        $state = I('get.state');
        $starttime = I('get.starttime');
        $endtime = I('get.endtime');
        $page   = $this->http['p'] ? $this->http['p'] : 1;
        $list   = D('Withdraw')->search($status,$state,$page,$starttime,$endtime);
        $result     = array(
            'applys'     => $list,
            'pages' => $page
        );
        $this->outOInfo($result);
    }


    /**
     * 更改提现状态
     */
    public function firstchangestaus(){
        $id =  I('get.id');
        $status = I('get.status');
        $remark     = I('get.remark');
        if (empty($id)){
            $this->outOInfo('请选择要操作的数据!', 0);
        }
        $result= D('Withdraw')->change($id,$status,$remark);
        $this->outOInfo($result);
    }
    public function secondchangestaus(){
        $id =  I('get.id');
        $status = I('get.status');
        $remark     = I('get.remark');
        if (empty($id)){
            $this->outOInfo('请选择要操作的数据!', 0);
        }
        $result= D('Withdraw')->change($id,$status,$remark);

        if($result==1){
            $this->outOInfo($result);
        }else{
            $this->outOInfo($result,0);
        }

    }

    /**
     * 导出提现信息Excel
     *
     */
    function outList(){
        $status = I('get.status');
        $state = I('get.state');
        $starttime = I('get.starttime');
        $endtime = I('get.endtime');
        $user_title = $this->status_titles[$status];
        $title  = array(
            '提现ID',
            '用户昵称',
            '真实姓名',
            '申请时间',
            '申请金额',
            '可申请金额',
            '累计提现金额',
        );
        $key    = array(
            'id',
            'nickname',
            'truename',
            'create_time',
            'apply_amount',
            'wallet',
            'has_apply',

        );
        $list   = D('Withdraw')->getList($status,$state,$starttime,$endtime);
        foreach($list as $val){
            foreach($key as $k){
                $info[$k]   = $val[$k];
            }
            $data[]     = $info;
        }

        out_excel($title, $data, '欣乐土提现数据-'.$user_title);
    }
    /**
     * 获取税率
     */
    public function tax(){
        $list   = M('config')->where("id=1")->field('wd_tax_rate')->find();
        $result     = array(
            'tax'     => $list['wd_tax_rate']
        );
        $this->outOInfo($result);
    }
    /**
     * 修改税率
     */
    public function adtax(){
        $tax['wd_tax_rate'] = I('get.tax');
        $list   = M('config')->where("id=1")->field('wd_tax_rate')->find();
        if($list){
            $result   = M('config')->where("id=1")->save($tax);
        }else{
            $result   = M('config')->add($tax);
        }

        $this->outOInfo($result);
    }
}